package com.wnxy.sddfp.search.controller;

import com.wnxy.sddfp.common.model.query.Pages;
import com.wnxy.sddfp.common.model.result.Result;
import com.wnxy.sddfp.search.model.query.BorrowRecordSearchQuery;
import com.wnxy.sddfp.search.service.SearchService;
import com.wnxy.sddfp.search.vo.BorrowRecordIndexVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/search")
@Api(tags = "搜索服务")
@RefreshScope
public class SearchController {

    private static final Logger log = LoggerFactory.getLogger(SearchController.class);
    @Autowired
    private SearchService searchService;
    @Value("${search.title}")
    private String title;

    @PostMapping("/test")
    @ApiOperation("测试")
    public String test() {
        System.out.println("配置文件读取 = " + title);
        log.info("测试");
        return "配置文件读取 = " + title;
    }

    @PostMapping("/borrowRecord")
    @ApiOperation("查询借款记录")
    public Result search(@RequestBody BorrowRecordSearchQuery borrowRecordSearchQuery) {
        Pages<BorrowRecordIndexVo> pages =
                searchService.search(borrowRecordSearchQuery);
        return Result.ok(pages);
    }
}